package fragments;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.CardView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.baseproject.BaseFragment;
import com.example.administrator.newxlmedical.CardinalNumberActivity;
import com.example.administrator.newxlmedical.ComboSetActivity;
import com.example.administrator.newxlmedical.CountActivity;
import com.example.administrator.newxlmedical.OpenDoorActivity;
import com.example.administrator.newxlmedical.R;
import com.example.administrator.newxlmedical.SearchActivity;
import com.example.administrator.newxlmedical.SetActivity;
import com.example.administrator.newxlmedical.UserActivity;

import beans.NewUserInfoBean;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import constants.Constants;
import utils.ActivityUtil;
import utils.ObjectSaveUtil;

/**
 * A simple {@link Fragment} subclass.
 */
public class MenuSecondFragment extends BaseFragment {

    @BindView(R.id.cv_second_menu_search)
    CardView cvSearch;
    @BindView(R.id.cv_second_menu_user)
    CardView cvUser;
    @BindView(R.id.cv_second_menu_count)
    CardView cvCount;
    @BindView(R.id.cv_second_menu_setting)
    CardView cvSetting;
    Unbinder unbinder;
    @BindView(R.id.cv_second_menu_base_setting)
    CardView cvSecondMenuBaseSetting;
    @BindView(R.id.cv_second_menu_combo_setting)
    CardView cvSecondMenuComboSetting;

    public MenuSecondFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_menu_second, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    protected void initView() {
        super.initView();
        NewUserInfoBean.DataBean dataBean = (NewUserInfoBean.DataBean) ObjectSaveUtil.readObject(mContext, Constants.USER_INFO_BEAN, Constants.USER_INFO_BEAN);
        int roleInfoId = dataBean.getRoleInfoId();
        if (roleInfoId == Constants.ROLE_NURSE || roleInfoId == Constants.ROLE_SUPPLIER) {
            cvUser.setVisibility(View.GONE);
        }

        if (roleInfoId == Constants.ROLE_SUPPLIER){
            cvSecondMenuBaseSetting.setVisibility(View.GONE);
            cvSecondMenuComboSetting.setVisibility(View.GONE);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.cv_second_menu_search, R.id.cv_second_menu_user, R.id.cv_second_menu_count, R.id.cv_second_menu_setting, R.id.cv_second_menu_base_setting,
            R.id.cv_second_menu_combo_setting})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.cv_second_menu_search:
                ActivityUtil.jumpToActivity(mContext, SearchActivity.class);
                break;
            case R.id.cv_second_menu_user:
                ActivityUtil.jumpToActivity(mContext, UserActivity.class);
                break;
            case R.id.cv_second_menu_count:
                Intent intent2 = new Intent(mContext, OpenDoorActivity.class);
                intent2.putExtra(Constants.OPEN_DOOR, Constants.CHECK);
                startActivity(intent2);
                break;
            case R.id.cv_second_menu_setting:
                ActivityUtil.jumpToActivity(mContext, SetActivity.class);
                break;
            case R.id.cv_second_menu_base_setting:
                ActivityUtil.jumpToActivity(mContext, CardinalNumberActivity.class);
                break;
            case R.id.cv_second_menu_combo_setting:
                ActivityUtil.jumpToActivity(mContext, ComboSetActivity.class);
                break;
        }
    }

}
